import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2024-03-16
 * Time: 16:20
 */
public class JDBCDemo3 {
    public static void main(String[] args) throws SQLException {
        /**
         * 删除数据库表中的内容
         */
        //1.建立数据源
        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource) dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/java111?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource)dataSource).setUser("root");
        ((MysqlDataSource)dataSource).setPassword("11111111");
        //2.建立连接
        Connection connection=dataSource.getConnection();
        //3.构造一个操作数据库的sql语句
        String sql="delete from student where name='张三'";
        PreparedStatement preparedStatement= connection.prepareStatement(sql);
        //4.执行sql
        int n=preparedStatement.executeUpdate();
        System.out.println("n= " +n);
        //5.释放资源
        preparedStatement.close();
        connection.close();
    }
}
